<?php
/*
File: domains.php
Version: 2.0
Date created: 
Last Edited : 26-07-2008
Author: Craig G Smith<craig@joomla-host.co.za
*/

  defined( 'JOSCOM_VERSION' ) or die( 'Direct Access to this location is not allowed.' );
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $cPath, $cPath_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require(DIR_WS_COMPONENT . 'includes/application_top.php');
  }
  
$action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : '');


?>
<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/stylesheet.css">
<script language="javascript" src="<?php echo DIR_WS_COMPONENT ?>includes/general.js"></script>

<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<?php
switch ($action) {

case "dosave":
//print_r($_POST);
$database->setQuery("Insert into " . TABLE_DOMAINS_PRICE . " values('','{$_POST['tld0']}','{$_POST['price0']}')");
$database->query();

$url = tep_href_link(FILENAME_DOMAINS, 'msg=' . TEXT_UPDATE_COMPLETE);
 tep_redirect($url);
break;
case "update":

//step 1 remove the deleted options
if(isset($_POST['dom'])){
foreach($_POST['dom'] as $key => $value){
$database->setQuery("Delete from " . TABLE_DOMAINS_PRICE . " where tld_id = '$key'");
$database->query();
}
}

//step 2-> update all prices 
foreach($_POST['price'] as $key => $value){
$database->setQuery("update " . TABLE_DOMAINS_PRICE . " set price = '$value' where tld_id = '$key'");
$database->query();

}

//show the page again
$url = tep_href_link(FILENAME_DOMAINS, 'msg=' . TEXT_UPDATE_COMPLETE);
 tep_redirect($url);
break;



case "add":
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo TABLE_HEADING_TLD_NEW; ?></td>
            <td class="pageHeading" align="right"></td>
          </tr>
          <tr><td colspan="2" class="main"><?php echo TEXT_ADD_TLD?></td></tr>
        </table>
        <table class="adminlist" cellspacing="1">
        <thead>
              <tr class="dataTableHeadingRow">
              
                <th class="dataTableHeadingContent"><?php echo TABLE_HEADING_TLD; ?></th>
                <th class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRICE; ?></th>
                
              </tr>
              </thead>
         <?php     echo    tep_draw_form('domains', tep_href_link(FILENAME_DOMAINS), "POST"); ?>
              <tr><td><input type="text" name="tld0"></td><td><input type="text" name="price0"></td></tr>
       
              <tr><td><input type="hidden" name="action" value="dosave"></td><td> <?php echo tep_image_submit('button_save.gif', IMAGE_SAVE);?></td></tr></form>
<?php              

break;

default:
$database->setQuery("Select * from " . TABLE_DOMAINS_PRICE . " order by tld asc");
$domlist = $database->loadObjectList();
?>


<!-- header_eof //-->
<table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE ?></td>
            <td class="pageHeading" align="right"></td>
          </tr>
        </table>
        <table class="adminlist" cellspacing="1">
        <thead>
              <tr class="dataTableHeadingRow">
              <th class="dataTableHeadingContent" align="right"><?php echo TEXT_INFO_HEADING_DELETE_TLD; ?></th>
                <th class="dataTableHeadingContent"><?php echo TABLE_HEADING_TLD; ?></th>
                <th class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRICE; ?></th>
                
              </tr>
<?php
$row = 0;
echo    tep_draw_form('domains', tep_href_link(FILENAME_DOMAINS), "POST");

foreach($domlist as $domdet){
?>
<tr class="dataTableRow<?php echo $row;?>" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">
<td><input type="checkbox" name="dom[<?php echo $domdet->tld_id;?>]"></td>
<td><strong><?php echo $domdet->tld;?></td>
<td><input type="text" name="price[<?php echo $domdet->tld_id;?>]" value="<?php echo $domdet->price;?>"></td></tr>

<?php
$row = 1 - $row;
}
?>
<tr><input type="hidden" name="action" value="update"><td></td><td></td><td><?php echo tep_image_submit('button_update.gif', IMAGE_UPDATE);?> &nbsp; <a href="<?php echo tep_href_link(FILENAME_DOMAINS , 'action=add');?>"><?php echo tep_image_button('button_insert.gif', IMAGE_INSERT) . '</a>'; ?></a></td></tr>
<?php
break;
}

?>
</tr>
        </table></form></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); 


 require(DIR_WS_INCLUDES . 'application_bottom.php');
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
